#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018\9\5 0005 16:31
# @Author  : never mind
# @File    : utils_list.py
import copy
import numpy as np
import constants as cons

def flat_list(lists):
    if len(lists) != 0 and type(lists[0][0]) == list and  type(lists[0][0][0]) != list:
        new_list = list()
        for item in lists:
            new_list.extend(item)
        return new_list
    else:
        print('lists not true')

def is_equal(item_1, item_2):
    if np.shape(item_1) != np.shape(item_2):
        print('%s must have the same shape as %s' % (item_1, item_2))
        return False
    if item_1 != item_2:
        return False
    else:
        return True

def get_reverse_list(pre_list):
    new_list = []
    length = len(pre_list)
    for i in range(length):
        new_list.append(pre_list[length-1-i])
    return new_list

def extend_occupid(occ_, extend_trace_):
    temp = []
    for item in occ_:
        temp.append(item)
    for item in extend_trace_:
        if item not in occ_:
            temp.append(item)
    return temp

def get_copied_list(occ, item=[0, 0], op='other'):
    temp = copy.copy(occ)
    if op == 'append':
        temp.append(item)
    elif op == 'remove':
        temp.remove(item)
    else:
        pass
    return temp

def get_copied(item):
    return copy.copy(item)

def print_list(occ):
    for item in occ:
        print("occupied position %s" % item)

def out_pair(occ_pair, occ):
    if len(occ) == 0:
        print("there is no car in the park.")
        return False
    if occ_pair not in occ:
        print("there is no car in the position %s " % occ_pair)
        return False
    if occ_pair in cons.pos_in or occ_pair in cons.pos_out:
        print('it is in or out position.')
        return False
    print('move out %s' % occ_pair)
    return True